package com.siashan.toolkit.sms.core.entity;

import lombok.Data;

/**
 * 短信发送结果
 *
 * @author siashan
 * @since v1.0.1
 */
@Data
public class SmsSendResult {

    /**
     * 是否发送成功
     */
    private boolean success;

    /**
     * 频率校验是否通过
     */
    private boolean frequnecyPass;

    /**
     * 响应码
     */
    private String code;

    /**
     * 响应消息
     */
    private String errMsg;


    public static SmsSendResult sendSuccess(String msg){
        SmsSendResult result = new SmsSendResult();
        result.setSuccess(true);
        result.setFrequnecyPass(true);
        result.setErrMsg(msg);
        return result;
    }

    public static SmsSendResult sendSuccess(){
        return sendSuccess("短信发送成功");
    }

    public static SmsSendResult sendResult(boolean success){
        SmsSendResult result = new SmsSendResult();
        result.setSuccess(success);
        result.setFrequnecyPass(true);
        result.setErrMsg(success ? "短信发送成功" : "短信发送失败");
        return result;
    }


    public static SmsSendResult sendFail(){
        return sendFail(true,"短信发送失败");
    }

    public static SmsSendResult sendFail(boolean frequnecyPass,String errMsg){
        SmsSendResult result = new SmsSendResult();
        result.setSuccess(false);
        result.setFrequnecyPass(frequnecyPass);
        result.setErrMsg(errMsg);
        return result;
    }

    public static SmsSendResult frequnecyCheckFail(SmsFrequencyResult smsFrequencyResult){
        return sendFail(false,smsFrequencyResult.getDesp());
    }

}
